import 'package:bloc/bloc.dart';
import 'package:flutter/rendering.dart';
import 'package:f_demo/bloc/index.dart';
import 'package:f_demo/generated/i18n.dart';

class LanguageBloc extends Bloc<LanguageEvent, LanguageState>{
  @override
  LanguageState get initialState => LanguageState(local: Locale('en', 'US'));

  @override
  Stream<LanguageState> mapEventToState(LanguageEvent event) async* {
    if(event is UpdateLanguageEvent){
      List _localList = event.local.split('_');
      Locale _locale = Locale(_localList[0], _localList[1]);
      I18n.locale = _locale;
      yield LanguageState(local: _locale);
    }
  }
}